package com.weeasy.auth.controller;

import com.weeasy.core.common.Result;
import com.weeasy.auth.service.AuthService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 微信认证控制器
 * 
 * @author we-easy
 * @since 1.0.0
 */
@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
@CrossOrigin(origins = "*")
public class AuthController {

    private final AuthService authService;

    /**
     * 微信授权登录
     * 
     * @param code 授权码
     * @return 认证结果
     */
    @PostMapping("/login")
    public Result<String> authLogin(@RequestParam String code) {
        String result = authService.authLogin(code);
        return Result.success("授权登录成功", result);
    }

    /**
     * 获取用户信息
     * 
     * @return 用户信息
     */
    @GetMapping("/userinfo")
    public Result<String> getUserInfo() {
        String userInfo = authService.getUserInfo();
        return Result.success("获取用户信息成功", userInfo);
    }
}
